<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.db.conn"%>
<%@ page import="com.db.Pagination"%>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<jsp:include flush="true" page="${basePath}/admin/head.jsp"></jsp:include>
 <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">管理优惠券信息</h3>
            </div>
            <div class="panel-body" style="min-height: 500px;">
           <table style="width:100%;"><tr><td align="center">
  <table class="layui-table" style="width:98%;margin-left:10px;" align="center">
                    <tbody>
                 <tr>
                <td align="center">
                       </td>
            </tr>
             <tr>
                <td align="center">
                      <%
//定义四个分页会用到的变量
int pageSize=15;
int pageNow=1;//默认显示第一页
int rowCount=0;//该值从数据库中查询
int pageCount=0;//该值是通过pageSize和rowCount
//接受用户希望显示的页数（pageNow）
String s_pageNow=request.getParameter("pageNum");
if(s_pageNow!=null){
//接收到了pageNow
pageNow=Integer.parseInt(s_pageNow);
}

String where="  1=1 ";

conn cn=new conn();


ResultSet rs=cn.query("select count(*) from coupon a where "+where);
if(rs.next()){
rowCount=rs.getInt(1);
}

//计算pageCount
if(rowCount%pageSize==0){
pageCount=rowCount/pageSize;
}else{
pageCount=rowCount/pageSize+1;
}
//查询出需要显示的记录
 
rs=cn.query("select  * from coupon a where "+where+" order by cid desc limit "+pageSize*(pageNow-1)+", "+pageSize);

%>

	<table cellspacing="0" border="0" style="width:100%;border-collapse:collapse;"  >
		<tr>
    <th >优惠券标题</th>
    <th >优惠券图片</th>
    <th >满</th>
    <th >减</th>
    <th >库存数量</th>
			<th scope="col">操作</th>		</tr>
		<%
while(rs.next()){
%>
		<tr align="center" >
  			<td><%=rs.getString("ctitle") %></td>
 <td align="center"><img alt="" src="<%=path %>//<%=rs.getString("cphoto") %>" width="80"  height="80" /></td>
  			<td><%=rs.getString("cman") %></td>
  			<td><%=rs.getString("cjian") %></td>
  			<td><%=rs.getString("cquan") %></td>
			<td >
           <a href="<%=path %>/admin/coupon/coupon_Edit.jsp?id=<%=rs.getString("cid") %>">编辑</a>&nbsp;
           <a href="<%=path %>/coupon_Delete?id=<%=rs.getString("cid") %>">删除</a>
		</tr>
<%} %>
  
					   </table>
             		 <table width=100%>
			 <tbody>
               <tr>
                <td align="center">
                       <%= Pagination.getPagination(pageNow,pageCount,rowCount,request.getRequestURI()) %>    
              </td>
              </tr>
                    </tbody>
                </table>
   </td></tr></table>
            

            </div>
        </div>




